const cow_skin = cc.Class({
    name:'cow_skin',
    properties:{
        cow_skins:{
            default:[],
            type: [cc.SpriteFrame]
        }
    }
})

cc.Class({
    extends: cc.Component,


    properties: {
        cow_type:{
            default:[],
            type:[cow_skin]
        },
        
    },


    start () {
        //奶牛类型切换
        this.number =  Math.floor(Math.random() * this.cow_type.length);

        this.InterTime = 0;
    },

    update (dt) {
        this.InterTime += dt;
        //
        let index = Math.floor(this.InterTime / 0.2);
        let cowType= this.cow_type[this.number];
        let cowScript = this.node.getComponent(cc.Sprite);
        // index %=3;
        //换肤到最后一个，重置index
        if(index >= cowType.cow_skins.length){
            index = 0;
            this.InterTime = 0;
        }
        cowScript.spriteFrame = cowType.cow_skins[index];

    },

    runCallback(){
        this.number =  Math.floor(Math.random() * this.cow_type.length);
        cc.log("一只牛跑过去了")
    }
});
